﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace TeamNitro
{
    public partial class AdminSignUpStudent : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnStuCreate_Click(object sender, EventArgs e)
        {
            List<DBManager> list = DBManager.GetUser("Student");
            bool flag = true;

            for (int i = 0; i < list.Count; i++)
            {
                if (tbxStuID.Text.Equals(list[i].StudentID, StringComparison.CurrentCultureIgnoreCase))
                {
                    flag = false;
                }
            }
            if (flag == true)
            {
                DBManager create = new DBManager();
                create.StudentID = tbxStuID.Text;
                create.StudentName = tbxStuName.Text;
                create.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(tbxStuPassword.Text, "sha1");
                create.ContactNumber = Convert.ToInt32(tbxStuContact.Text);
                create.Address = tbxStuAddress.Text;
                create.Email = tbxStuEmail.Text+lblEmailDomain.Text;
                create.CurrentYear = rblStuYear.SelectedValue;
                create.CurrentSem = rblStuSem.SelectedValue;
                create.School = rblStuSchool.SelectedValue;
                create.CourseName = tbxStuCourseName.Text;
                create.CourseCode = tbxStuCourseCode.Text;

                bool result = DBManager.InsertStudent(create);

                if (result == true)
                {
                    lblResult.Text = "Account Added Successfully!";
                    lblResult.ForeColor = System.Drawing.Color.Lime;
                    lblResult.Visible = true;
                }

                else
                {
                    lblResult.Text = "Account is not added!";
                    lblResult.ForeColor = System.Drawing.Color.Red;
                    lblResult.Visible = true;
                }

                tbxStuID.Text = String.Empty;
                tbxStuName.Text = String.Empty;
                tbxStuPassword.Text = String.Empty;
                tbxStuContact.Text = String.Empty;
                tbxStuAddress.Text = String.Empty;
                tbxStuEmail.Text = String.Empty;
                rblStuYear.ClearSelection();
                rblStuSem.ClearSelection();
                rblStuSchool.ClearSelection();
                tbxStuCourseName.Text = String.Empty;
                tbxStuCourseCode.Text = String.Empty;
            }

            else
            {
                lblResult.Text = "Account ID is already added!";
                lblResult.ForeColor = System.Drawing.Color.Red;
                lblResult.Visible = true;
            }

        }
    }
}